/*
 * author: VDaras
 */

#ifndef SURFACE_H
#define	SURFACE_H

#include "../NonCopyable.h"
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>

namespace sdl
{

class Color;

/*
 * Class wrapping the SDL_Surface struct. Provides an interface for further
 * surfaces to be derived from (like the screen, images etc.) and some
 * functionality.
 */

class Surface : public NonCopyable
{
private:
    SDL_Surface *m_buffer;

public:
    Surface();
    virtual ~Surface() = 0;
    
    /**
     * Converts this surface into a opengl 2d texture.
     * 
     * default for both filters is Linear
     * 
     * @param minFilter - Filter to use in case of minimization.
     * @param magFilter - Filter to use in case of maximazation.
     * @return The ID of the texture or 0 to describe failure.
     */
    GLuint ConvertToTexture(GLint minFilter = GL_LINEAR,GLint magFilter = GL_LINEAR);
    
    /**
     * Checks if buffer is valid or NULL.
     * @return 
     */
    bool Valid() const;
    
    int GetWidth() const;
    int GetHeight() const;
    
    /**
     * Sets the specified pixel at the given color.
     * @param x
     * @param y
     * @param color
     */
    void SetPixel(int x, int y, const sdl::Color &color);
    
    /**
     * Fills the given area with the specified color.
     * @param x
     * @param y
     * @param w
     * @param h
     * @param color
     */
    void FillArea(int x, int y, int w, int h, const sdl::Color &color);
    
    SDL_Surface *GetBuffer() const;
    //SDL_Surface *getMutableBuffer();
protected:
    void SetBuffer(SDL_Surface *buffer);
    void FreeBuffer();
};

};

#endif	/* SURFACE_H */

